package UI;

import javax.swing.*;
import javax.swing.border.BevelBorder;
import java.util.Random;

public class Game extends JFrame {
    int[][] data = new int[4][4];
    public Game() {
        initGame();

        initMenuBar();

        //初始化数据
        initData();

        initImage();
        //显示界面
        this.setVisible(true);
    }
    private void initData() {
        int[] arr = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
        Random r = new Random();
        for (int i = 0; i < arr.length; i++) {
            int index = r.nextInt(arr.length);
            int temp = arr[i];
            arr[i] = arr[index];
            arr[index] = temp;
        }
        for (int i = 0; i < arr.length; i++) {
            data[i / 4][i % 4] = arr[i];
        }
    }

    private void initGame() {
        //设置界面宽高
        this.setSize(600, 680);

        //设置界面标题
        this.setTitle("拼图小游戏 V1.0");

        //设置界面置顶
        this.setAlwaysOnTop(true);

        //设置界面剧中
        this.setLocationRelativeTo(null);

        //设置关闭模式
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

        this.setLayout(null);
        //设置icon
        this.setIconImage(null);

        //创建按钮对象

    }

    private void initMenuBar() {
        //设置菜单
        //创建整个菜单对象
        JMenuBar menuBar = new JMenuBar();

        //创建菜单上面的连个选项
        JMenu FunctionJMenu = new JMenu("功能");
        JMenu AboutJMenu = new JMenu("关于我们");

        //选项下面的条目
        JMenuItem replayItem = new JMenuItem("重新游戏");
        JMenuItem reloginItem = new JMenuItem("重新登录");
        JMenuItem closeItem = new JMenuItem("关闭游戏");
        JMenuItem accountItem = new JMenuItem("公众号");

        FunctionJMenu.add(replayItem);
        FunctionJMenu.add(reloginItem);
        FunctionJMenu.add(closeItem);
        AboutJMenu.add(accountItem);

        menuBar.add(FunctionJMenu);
        menuBar.add(AboutJMenu);


        this.setJMenuBar(menuBar);
    }

    private void initImage() {

        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 4; j++) {
                int n = data[i][j];
                ImageIcon imageIcon = new ImageIcon("E:\\java\\java\\game\\UI\\image\\animal\\animal3\\" + n + ".jpg");
                JLabel imageLabel = new JLabel(imageIcon);
                imageLabel.setBounds(105 * j +83, 105 * i +134, 105, 105);
                imageLabel.setBorder(new BevelBorder(0));
                this.getContentPane().add(imageLabel);
            }
        }
        JLabel background = new JLabel(new ImageIcon("E:\\java\\java\\game\\UI\\image\\background.png"));
        background.setBounds(40,40,508,560);
        this.getContentPane().add(background);

    }
}
